<template>
	<view>
		<view class="top">
			<view class="top_1" @click="clickBack()">
				<image src="../../static/images/detail/back.png" mode=""></image>
			</view>
			<view class="top_2">
				<text :class="titleIndex == 0 ? 'text_active' : ''" @click="clickTitle(0)">收到得招呼</text>
				<text :class="titleIndex == 1 ? 'text_active' : ''" @click="clickTitle(1)">发出得招呼</text>
			</view>
		</view>
		
		<view class="top1" v-if="titleIndex == 0">
			<view class="cont" v-for="(item,index) in dataList" v-bind:key='index'>
				<view class="left">
					<image :src="item.user.avatar" mode="" @click="clickZhao(item)"></image>
				</view>
				<view class="right">
					<view class="right_1">
						<text>{{item.user.nick_name}}</text>
						<image v-if="item.user.sex == 'M'" src="../static/image/nan_sign.png" mode=""></image>
						<image v-if="item.user.sex == 'N'" src="../static/image/nv_sign.png" mode=""></image>
					</view>
					<view class="right_2">
						<text class="vip" v-if="item.user.vip != -1">{{item.user.vip}}</text>
						<text class="age" v-if="item.user.age">{{item.user.age}}岁</text>
						<text class="yuanfen" v-if="item.user.fate_value">缘分值{{item.user.fate_value}}</text>
					</view>
					<view class="right_3">
						<text>{{item.message}}</text>
					</view>
					
					<view class="right_4">
						<view class="right_4_1">
							{{item.time}}
						</view>
						<view class="right_4_2">
							<text class="jujue" v-if="item.applyStatus == 0" @click.stop="jujue(item)">拒绝</text>
							<text class="huifu" v-if="item.applyStatus == 0" @click.stop="tongyi(item)">同意</text>
							<text class="yigoutong" style="background: #FF5998;" v-if="item.applyStatus == 1"></text>
							<text class="goutong" v-if="item.applyStatus == 1">已同意</text>
							<text class="yigoutong" style="background: #8389A0;" v-if="item.applyStatus == 2"></text>
							<text class="goutong" v-if="item.applyStatus == 2">已拒绝</text>
						</view>
					</view>
					<view class="xian"></view>
				</view>
			</view>
		</view>
		
		
		<view class="top1" v-if="titleIndex == 1">
			<view class="cont" v-for="(item,index) in dataList1" v-bind:key='index'>
				<view class="left">
					<image :src="item.beApplied_user.avatar" mode="" @click="clickZhao1(item)"></image>
				</view>
				<view class="right">
					<view class="right_1">
						<text>{{item.beApplied_user.nick_name}}</text>
						<image v-if="item.beApplied_user.sex == 'M'" src="../static/image/nan_sign.png" mode=""></image>
						<image v-if="item.beApplied_user.sex == 'N'" src="../static/image/nv_sign.png" mode=""></image>
					</view>
					<view class="right_2">
						<text class="vip" v-if="item.beApplied_user.vip != -1">{{item.beApplied_user.vip}}</text>
						<text class="age" v-if="item.beApplied_user.age">{{item.beApplied_user.age}}岁</text>
						<text class="yuanfen" v-if="item.beApplied_user.fate_value">缘分值{{item.beApplied_user.fate_value}}</text>
					</view>
					<view class="right_3">
						<text>{{item.message}}</text>
						<!-- <image src="../static/image/hua.png" mode=""></image> -->
					</view>
					
					<view class="right_4">
						<view class="right_4_1">
							{{item.time}}
						</view>
						<view class="right_4_2">
							<text v-if="item.applyStatus == 0" class="daihuifu">待回复</text>
							<text class="yigoutong" style="background: #FF5998;" v-if="item.applyStatus == 1"></text>
							<text class="goutong" v-if="item.applyStatus == 1">已沟通</text>
							<text class="yigoutong" style="background: #8389A0;" v-if="item.applyStatus == 2"></text>
							<text class="goutong" v-if="item.applyStatus == 2">已拒绝</text>
						</view>
					</view>
					<view class="xian"></view>
				</view>
			</view>
		</view>
		
		
		
		
	</view>
</template>

<script>
	import {
		applyList,
		processApply,
		apply
	} from '@/api/call/call.js';
	export default {
		data() {
			return {
				titleIndex : 0,
				dataList : [
					
				],
				dataList1 : [],
				allList : [],
			}
		},
		mounted() {
			this.getList();
		},
		methods: {
			clickZhao1(e){
				console.log(e.beApplied_user.user_id)
				uni.navigateTo({
					url: `/pageA/homepage/homepage?user_id=${e.beApplied_user.user_id}`
				});
			},
			clickZhao(e){
				uni.navigateTo({
					url: `/pageA/homepage/homepage?user_id=${e.user_id}`
				});
			},
			tongyi(e){
				var data = {
					applyID : e._id,
					operate : 1
				}
				processApply(data).then(res => {
					console.log(res);
					if(res.status == 1){
						uni.showToast({
							title:'操作成功',
							icon:"none"
						})
						this.getList();
					}
				})
			},
			jujue(e){
				console.log(e);
				var data = {
					applyID : e._id,
					operate : 2
				}
				processApply(data).then(res => {
					console.log(res);
					if(res.status == 1){
						uni.showToast({
							title:'操作成功',
							icon:"none"
						})
						this.getList();
					}
				})
			},
			clickBack(){
				uni.navigateBack();
			},
			getList(){
				applyList().then(res => {
					for(var i = 0;i < res.data.applyList.length;i++){
						res.data.applyList[i].time = this.getHouer(res.data.applyList[i].applyTime)
					}
					for(var i = 0;i < res.data.beAppliedList.length;i++){
						res.data.beAppliedList[i].time = this.getHouer(res.data.beAppliedList[i].applyTime)
					}
					this.allList = res.data;
					this.dataList = this.allList.beAppliedList
					console.log(this.dataList)
				})
			},
			getHouer(data){
				var  date = new Date(data);
				var hours = date.getHours();
				var minutes = date.getMinutes();
				return hours + ':' + minutes
			},
			clickTitle(e){
				this.titleIndex = e;
				if(e == 0){
					this.dataList = this.allList.beAppliedList;
				}else{
					this.dataList1 = this.allList.applyList;
					// this.apply();
				}
			},
			apply(){
				var data = {};
				apply(data).then(res => {
					console.log(res);
				})
			}
		}
	}
</script>

<style lang="scss">
	.cont{
		display: flex;
		.right{
			.xian{
				width: 530upx;
				height: 2upx;
				background-color: #DFE1EC;
				margin-top: 14upx;
			}
			width: 76%;
			.right_4{
				.right_4_2{
					.daihuifu{
						width: 120upx;
						height: 60upx;
						background: linear-gradient(135deg, #FC4F91 0%, #FD6CE6 100%);
						border-radius: 4upx;
						text-align: center;
						line-height: 60upx;
						font-size: 30upx;
						color: #FFFFFF;
						margin-right: 40upx;
					}
					.yigoutong{
						width: 12upx;
						height: 12upx;
						border-radius: 50%;
						margin-top: 18upx;
						margin-right: 18upx;
					}
					.goutong{
						color: #474A58;
						font-size: 30upx;
						margin-right: 40upx;
					}
					display: flex;
					.huifu{
						width: 120upx;
						height: 60upx;
						background: linear-gradient(135deg, #FC4F91 0%, #FD6CE6 100%);
						border-radius: 4upx;
						text-align: center;
						line-height: 60upx;
						color: #FFFFFF;
						font-size: 30upx;
						margin-top: 10upx;
						margin-right: 40upx;
						margin-left: 10upx;
					}
					.jujue{
						margin-top: 10upx;
						width: 120upx;
						height: 60upx;
						text-align: center;
						line-height: 60upx;
						border-radius: 4upx;
						border: 2upx solid #DFE1EC;
						background-color: #FFFFFF;
						color: #474A58;
						font-size: 30upx;
					}
				}
				.right_4_1{
					color: #8389A0;
					font-size: 26upx;
					margin-top: 22upx;
				}
				display: flex;
				justify-content: space-between;
			}
			.right_3{
				display: flex;
				text{
					color: #8389A0;
					font-size: 30upx;
				}
				image{
					width: 36upx;
					height: 36upx;
					margin-left: 4upx;
				}
				margin-top: 20upx;
			}
			.right_2{
				display: flex;
				.vip{
					width: 68upx;
					height: 36upx;
					border-radius: 4upx;
					border: 2upx solid #FFAA37;
					color: #FFAA37;
					font-size: 22upx;
					background: rgba(255,170,55,.5);
					text-align: center;
					line-height: 36upx;
				}
				.age{
					width: 68upx;
					height: 36upx;
					border-radius: 4upx;
					border: 2upx solid #2D8EFF;
					font-size: 22upx;
					color: #2D8EFF;
					background: rgba(45,142,255,.5);
					margin-left: 10upx;
					text-align: center;
					line-height: 36upx;
				}
				.yuanfen{
					width: 114upx;
					height: 36upx;
					background: #FFF3F8;
					border-radius: 4upx;
					border: 2upx solid #FF5998;
					color: #FF5998;
					font-size: 22upx;
					margin-left: 10upx;
					background: rgba(255,89,152,.5);
					text-align: center;
					line-height: 36upx;
				}
			}
			.right_1{
				display: flex;
				margin-top: 26upx;
				image{
					width: 42upx;
					height: 42upx;
				}
				text{
					color: #474A58;
					font-size: 34upx;
					margin-right: 10upx;
				}
			}
			display: flex;
			flex-direction: column;
		}
		.left{
			image{
				width: 126upx;
				height: 126upx;
				margin-left: 40upx;
				margin-right: 20upx;
				margin-top: 26upx;
				border-radius: 50%;
			}
		}
	}
	page{
		background-color: #FFFFFF;
	}
	.top{
		display: flex;
		margin-top: 36upx;
		.top_1{
			margin-top: 58upx;
			margin-left: 30upx;
			image{
				width: 50upx;
				height: 50upx;
			}
		}
		.top_2{
			display: flex;
			margin-top: 60upx;
			margin-left: 140upx;
			text{
				color: #8389A0;
				font-size: 30upx;
			}
			text:nth-of-type(2){
				margin-left: 30upx;
			}
			.text_active{
				color: #FF5998;
				font-size: 30upx;
				position:relative;
			}
			.text_active:after {
			     position: absolute;
			     bottom: -4upx;
				 width: 60upx;
				 height: 6upx;
			     left: 40upx;
			     content: '';
			     background-color: #FF5998;              //这个是唯佳的线颜色
			}
		}
	}
</style>